from leetcode_test import TreeNode


class Solution:
    def minDepth(self, root: TreeNode) -> int:

        if not root:
            return 0
        if not root.left and root.right:
            return self.minDepth(root.right) + 1
        if not root.right and root.left:
            return self.minDepth(root.left) + 1

        return 1 + min(self.minDepth(root.left), self.minDepth(root.right))


def test():
    t = TreeNode.create([1, 2])
    assert Solution().minDepth(t) == 2


def test1():
    t = TreeNode.create([3, 9, 20, None, None, 15, 7])
    assert Solution().minDepth(t) == 2


if __name__ == "__main__":
    t = TreeNode.create([1, 2])
    print(Solution().minDepth(t))

